package com.qianhui.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.qianhui.pojo.Buyer;
import org.apache.struts2.ServletActionContext;

public class BuyerLoginInterceptor extends AbstractInterceptor
{

    @Override
    public String intercept(ActionInvocation invocation) throws Exception
    {
        String actionName = ServletActionContext.getActionMapping().getName();
        // 如果是登录、注册、退出的话就不要拦截了
        if (actionName.equals("exit") || actionName.equals("login") || actionName.equals("login_do") || actionName.equals("regist") || actionName.equals("regist_do"))
        {
            return invocation.invoke();
        }
        // 如果不是买家就不能进入
        Buyer buyerTemp = (Buyer) ServletActionContext.getRequest().getSession().getAttribute("buyerSession");
		/*if (buyerTemp == null)
		{
			BuyerDAO buyerDAO = new BuyerDAO();
			buyerTemp = buyerDAO.findById("1509012100172385593097075");
			if (buyerTemp != null)
			{
				ServletActionContext.getRequest().getSession().setAttribute("buyerSession", buyerTemp);
			}
		}*/
        if (buyerTemp == null)
        {
            return "login";
        }
        return invocation.invoke();
    }

}
